<?php
//@session_start();
date_default_timezone_set ( 'Asia/SHANGHAI' );//设置时区
function Rqt($obj) {
	$tmp = "";
	$returnvalue = "";
	$str="select,delete,update,create,drop,and";
	$arr=explode(',',$str);
	$tmp = $_GET [$obj] != '' ? $_GET [$obj] : $_POST [$obj];
	$tmp2=strtolower($tmp);
	$tmp2=str_replace("'",'',$tmp2);
	if (in_array($tmp2,$arr)) {
		$msg = "获取参数错误，请检查您所提交的数据！以下为不能被提交的数据：\n\n$tmp .";
		echo '<script>top.location.href="/Error.php?msg=' . urlencode ( $msg ) . '";</script>';
	} else {
		$returnvalue = $tmp;
	}
	return $returnvalue;
}




function Post($obj) {
	$myi = 0;$tmp = ''; $value = '';
	$str='select,delete,update,create,drop,insert,iframe';
	$arr=explode(',',$str);
	//echo $obj.':'.$_POST [$obj].'<br/>';
	$tmp = trim($_POST [$obj]);
	$tmp=str_replace("'",'',$tmp);
	$tmp=str_replace('<','&lt;',$tmp);
	$tmp=str_replace('>','&gt;',$tmp);

	if (! empty ( $tmp )) {
		if (strtolower(gettype ( $tmp )) != 'array') {
			$val = strtolower ( $tmp );
			if (in_array($val,$arr)) {
				$msg = "获取参数错误，请检查您所提交的数据！以下为不能被提交的数据：\n\n$tmp .";
				echo '<script>top.location.href="/Error.php?msg=' . urlencode ( $msg ) . '";</script>';
			}
			$value = $tmp;
		} else {
			foreach ( $tmp as $item ) {
				$myi ++;
				$value .= $myi == count ( $tmp ) ? $item : $item . ',';
			}
		}
	} else {
		$value = $tmp;
	}
	return $value;
}


function Get($obj) {
	$myi = 0;
	$tmp = "";
	$returnvalue = "";
	$str="select,delete,update,create,drop,insert";
	$arr=explode(',',$str);
	$tmp = trim($_GET [$obj]);
	$tmp=str_replace("'",'',$tmp);
	if (! empty ( $tmp )) {
		if (gettype ( $tmp ) != 'array') {
			$val = strtolower ( $tmp );
			if (in_array($val,$arr)) {
				$msg = "获取参数错误，请检查您所提交的数据！以下为不能被提交的数据：\n\n$tmp .";
				echo '<script>top.location.href="/Error.php?msg=' . urlencode ( $msg ) . '";</script>';
			}
			$returnvalue = $tmp;
		} else {
			foreach ( $tmp as $item ) {
				$myi ++;
				$returnvalue .= $myi == sizeof ( $tmp ) ? $item : $item . ',';
			}
		}
	} else {
		$returnvalue = $tmp;
	}
	return $returnvalue;
}

function GetIp() {
	$IP = ($_SERVER ["HTTP_VIA"]) ? $_SERVER ["HTTP_X_FORWARDED_FOR"] : $_SERVER ["REMOTE_ADDR"];
	$IP = ($IP) ? $IP : $_SERVER ["REMOTE_ADDR"];
	return $IP;
}

function GetUrl($model=0) {
	$url='http://' . $_SERVER ['SERVER_NAME'] . ':' . $_SERVER ["SERVER_PORT"] . $_SERVER ["REQUEST_URI"];
	$url=0==$model ? $url : urlencode($url);
	return $url;
}

function GetLongUrl(){
	$url='http://' . $_SERVER ['SERVER_NAME'] . ':' . $_SERVER ["SERVER_PORT"] . $_SERVER ["REQUEST_URI"];
	$u = explode('?',$url);
	return $u[0];
}


function Alert($tipContent) {
	@header("Content-Type:text/html;charset=utf-8");
	echo '<script type="text/javascript">alert("'.$tipContent.'");</script>';
}

function Alert_Back($tipContent) {
	@header("Content-Type:text/html;charset=utf-8");
	echo '<script type="text/javascript">alert("'.$tipContent.'");history.go(-1);</script>';
	die();
}

function Alert_Url($tipContent='操作成功', $Url) {
	@header("Content-Type:text/html;charset=utf-8");
	echo '<script type="text/javascript">alert("'.$tipContent.'");location.href="'.$Url.'";</script>';
	//require_once(ADMINI_TPL."success.html");
	die();
}

function Alert_Close($tipContent) {
	@header("Content-Type:text/html;charset=utf-8");
	echo '<script type="text/javascript">alert("'.$tipContent.'");window.close();</script>';
	die();
}

function Location($Url) {
	@header("Content-Type:text/html;charset=utf-8");
	echo '<script type="text/javascript">location.href="'.$Url.'";</script>';
	die();
}

function cutStr($strInput,$intLength,$intStart=0,$strCode='utf-8'){
	$strInput=str_replace("&nbsp;"," ",$strInput);
	if(mb_strlen($strInput,$strCode)>$intLength){
		return(mb_substr($strInput,$intStart,$intLength,$strCode)."...");
	}else{
		return $strInput;
	}
}

function Login_Alert_Url($tipContent, $Url) {
	@header("Content-Type:text/html;charset=utf-8");
	echo '<script type="text/javascript">alert("'.$tipContent.'");location.href="'.$Url.'";</script>';
}
/** 跨天航班的到达时间的显示 如:"第二天的19:00”转换成“19:00+1"*
* @param $sendTime			起飞时间
* @param $arrivalTime		到达时间
* @return String
*/
function getJou_arrival_time($sendTime,$arrivalTime)
{
	$time=date("H:i",$arrivalTime);
	$days=(strtotime(date("Y-m-d",$arrivalTime))-strtotime(date("Y-m-d",$sendTime)))/86400;	//计算日期差
	if($days>0)		//日期差大于0则转变日期格式
	{
		$time=$time.'+'.$days;
	}
	return $time;
}
/*
* 自动导入类文件 并且实例化改类文件
* */
function import($data=""){
    global $root;
    global $menu;
    require_once(WEBROOT.$root."/class/".$menu.".class.php");
    return new $menu($data);
}
/*
*导入其他目录类文件 并且实例化
* */
function import_s($mode,$menu,$data=""){
    require_once(WEBROOT.$mode."/class/".$menu.".class.php");
    return new $menu($data);
}

/**
 * 加盟商订单状态
 * @return array
 */
function get_cst_ord_sts(){
	$ordSts=array(
	0=>'已取消', //数据表中0=>'已取消',
	1=>'新订单', //数据表中1=>'新订单',
	2=>'开票处理中', //数据表中###2=>'准备开票'###,3=>'等待付款',4=>'等待开票',
	3=>'已开票', //数据表中5=>'已开票',
	4=>'退票处理中', //数据表中6=>'准备退票',7=>'退票处理中',8=>'退票等待退款',9=>'退票等待结算',
	5=>'退票完成', //数据表中10=>'退票完成',
	6=>'废票处理中', //数据表中11=>'准备废票',12=>'废票处理中',13=>'废票等待退款',14=>'废票等待结算',
	7=>'废票完成', //数据表中15=>'废票完成'
	8=>'改期处理中', //16=>'准备改期',17=>'改期处理中',18=>'改期结算'
	9=>'改期完成' //19=>'改期完成'
	);
	return $ordSts;
}

/*==============================
 充值状态
 ==============================*/
function getStatus($tmp){
	switch($tmp){
		case "0":
			$title = "<span style='color:#ff9900; font-weight:normal;'>审核中...</span>";
			break;
		case "1":
			$title = "<span style='color:#0069ca; font-weight:normal;'>充值成功</span>";
			break;
		case "2":
			$title = "<span style='color:#FF0000; font-weight:normal;'>已作废</span>";
			break;
	}
	return $title;
}




/**
 * 统一数字格式
 * @param number $orginNumber 原始数字
 * @return number
 */
function money_frmt($orginNumber){
	return number_format($orginNumber,2,'.','');
}

/**
 * 城市名转换为三字码
 * @param   string     $name     城市名
 * @return  string     $symbol   三字码
 */
function symbol_change($name){
    global $db;
    $sql = "select airport_symbol from uu8_flight_airport where airport_cityname = '".$name."'";
    $array = $db->GetOneSql($sql);
    return $array['airport_symbol'];
}


/*
* 邮件发送
* @param $to 邮箱地址
* @param $subject 邮件主题
* @param $subject 邮件内容
*/

function phpmailer($to,$subject,$body) {
	$mail = new PHPMailer();
	$mail->IsSMTP();
	$mail->Host = "221.224.215.142:25";  // specify main and backup server
	$mail->SMTPAuth = true;     // turn on SMTP authentication
	$mail->Username = "postmaster@uu8uu8.com";  // SMTP username
	$mail->Password = "123465"; // SMTP password

	$mail->From = $mail->Username;
	$mail->FromName = "悠友吧商旅";
	$check_mail = $mail->AddAddress($to);

	$mail->WordWrap = 50;                                 // set word wrap to 50 characters
	$mail->IsHTML(true);                                  // set email format to HTM

	$mail->CharSet="utf-8";

	$mail->Subject = $subject;

	$mail->Body    = $body;

	$mail->AltBody = "This is the body in plain text for non-HTML mail clients";

	if($mail->Send())
	{
		return 'ok';
	}else{
		return 'error';
	}
}
// 输出数组或对象结构
function dump($o) {
	echo '<div style="text-align:left; border:1px solid #ccc; margin:10px; padding:10px; background:#eee; display:inline-block;">';
	echo '<pre>';
	print_r($o);
	echo '</pre>';
	echo '</div>';
	exit();
}


/*万能变量赋值打印
* @param paramName			待打印变量名称
* @param param			待打印变量
* @Return Void
* @sample:
	$param='';		#变量名称
	P($$param,$param);
*/
function P($param='',$paramName)
{
	if(is_array($param))
	{
		foreach($param as $k=>$v)
		{
			if(!is_array($v))
			{
				echo '$'.$paramName.'[\''.$k.'\'] = \''.$v.'\''.";<br/>\n";
			}
			else
			{
				P($v,$paramName.'[\''.$k.'\']');
			}
		}
	}
	else
	{
		echo '$'.$paramName.' = \''.$v.'\''.";<br/>\n";
	}
	echo "<br/>\n";
}

?>